package com.gridmobi.xrtb.handler;

import com.google.common.collect.Maps;
import com.gridmobi.xrtb.domain.dsp.JOffer;

import java.util.List;
import java.util.Map;
import java.util.Random;

public class ImprOffersHandler {

    public static Map<String, List<JOffer>> GEO_OS_MAP = Maps.newHashMap();
    static Random r = new Random();

    public static JOffer getRandomOffer(String geo2UP, String osNameLow) {
        String key = geo2UP + osNameLow;
        if (GEO_OS_MAP.containsKey(key)) {
            List<JOffer> offers = GEO_OS_MAP.get(key);
            int i = offers.size();
            if (i == 1) {
                return offers.get(0);
            } else {
                return offers.get(r.nextInt(i));
            }
        } else {
            return null;
        }
    }

}
